Ext.define('APP.view.nav.DefaultMenuItem',{
    alias : ['widget.defaultMenuItem'],
	defaultMenuItems:[
	{
		accordionText: '办公助理',
		treeConfig:{
	        expanded: true, 
	        children: [
	            { text: "detention", leaf: true ,command:'sayhello1'},
	            { text: "homework", expanded: true, children: [
	                { text: "book report", leaf: true ,command:'sayhello2'},
	                { text: "alegrbra", leaf: true,command:'sayhello3'}
	            ] },
	            { text: "buy lottery tickets", leaf: true ,command:'sayhello4'}
	        ]
	    }
		
	},
	{
		accordionText: '数据中心',
		treeConfig:{
	        expanded: true, 
	        children: [
	            { text: "detention", leaf: true },
	            { text: "homework", expanded: true, children: [
	                { text: "book report", leaf: true },
	                { text: "alegrbra", leaf: true}
	            ] },
	            { text: "buy lottery tickets", leaf: true }
	        ]
	    }
		
	}],
	getMenuPanelItems: function(items){
		var menuItems=[];
		var panelItems=[];
		if(!items)
			menuItems=this.defaultMenuItems;
		else
			menuItems=items;
		if(menuItems.length>0)
		{
			Ext.each(menuItems,function(item){
				panelItems.push({
					title: item.accordionText,
					store: Ext.create('Ext.data.TreeStore', {
					    root: item.treeConfig
					}),
					listeners: {
			    		'itemclick': function(self,node){
			    			var commandObj=Ext.commandMaps[node.raw.command];
			    			var intercept=false;
			    			if(!commandObj&&node.data.leaf)
			    			{
			    				Ext.Msg.alert('提示','当前命令没有配置,请确认！');
			    				return;
			    			}
			    			var tabsContainer=Ext.getCmp('tabsContainer');
			    			var newActiveTab;
			    			Ext.each(tabsContainer.items.items,function(tab){//检验该tab页是否已经显示
			    				//console.info('tab.commandObj:',tab.commandObj);
			    				//console.info('commandObj:',commandObj);
			    				newActiveTab= tab;
			    				if(Ext.util.cmpCmd(tab.commandObj,commandObj))
			    				{
			    					intercept=true
			    					return false;
			    				}
			    			});
			    			if(intercept)//如果已经存在，则设为活动的，并中断退出
			    			{
			    				tabsContainer.setActiveTab(newActiveTab);
			    				return;
			    			}

			    			var tabItem=Ext.ClassManager.instantiate(commandObj.className,commandObj.param);
			    			var tabItemPanel=Ext.create('widget.baseTab',{title:tabItem.title,items: tabItem})
			    			tabItemPanel.commandObj=commandObj;
			    			
			    			tabsContainer.add(tabItemPanel);
			    			tabsContainer.setActiveTab(tabItemPanel);
			    		}
			    	}
				});
			});
		}
		return panelItems;
	}


});
